/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.entity;

import java.io.ByteArrayInputStream;
import java.io.Serializable;
import java.math.BigDecimal;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

/**
 *
 * @author GiangLT
 */
@Entity
@Table(name = "SERVICE_INTRO", catalog = "", schema = "THIENLOC")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ServiceIntro.findAll", query = "SELECT s FROM ServiceIntro s"),
    @NamedQuery(name = "ServiceIntro.findById", query = "SELECT s FROM ServiceIntro s WHERE s.id = :id"),
    @NamedQuery(name = "ServiceIntro.findByServiceTitle", query = "SELECT s FROM ServiceIntro s WHERE s.serviceTitle = :serviceTitle"),
    @NamedQuery(name = "ServiceIntro.findByUrl", query = "SELECT s FROM ServiceIntro s WHERE s.url = :url"),
    @NamedQuery(name = "ServiceIntro.findByShortDescription", query = "SELECT s FROM ServiceIntro s WHERE s.shortDescription = :shortDescription"),
    @NamedQuery(name = "ServiceIntro.findByLongDescription", query = "SELECT s FROM ServiceIntro s WHERE s.longDescription = :longDescription"),
    @NamedQuery(name = "ServiceIntro.findByGeneral2", query = "SELECT s FROM ServiceIntro s WHERE s.general2 = :general2"),
    @NamedQuery(name = "ServiceIntro.findByGeneral3", query = "SELECT s FROM ServiceIntro s WHERE s.general3 = :general3"),
    @NamedQuery(name = "ServiceIntro.findByGeneral4", query = "SELECT s FROM ServiceIntro s WHERE s.general4 = :general4"),
    @NamedQuery(name = "ServiceIntro.findByGeneral5", query = "SELECT s FROM ServiceIntro s WHERE s.general5 = :general5")})
public class ServiceIntro implements Serializable {

    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @Basic(optional = false)
    @Column(name = "ID")
    private BigDecimal id;
    @Size(max = 1000)
    @Column(name = "SERVICE_TITLE")
    private String serviceTitle;
    @Size(max = 500)
    @Column(name = "URL")
    private String url;
    @Lob
    @Column(name = "IMAGE")
    private byte[] image;
    @Size(max = 1000)
    @Column(name = "SHORT_DESCRIPTION")
    private String shortDescription;
    @Size(max = 4000)
    @Column(name = "LONG_DESCRIPTION")
    private String longDescription;
    @Size(max = 4000)
    @Column(name = "GENERAL2")
    private String general2;
    @Size(max = 4000)
    @Column(name = "GENERAL3")
    private String general3;
    @Size(max = 4000)
    @Column(name = "GENERAL4")
    private String general4;
    @Size(max = 4000)
    @Column(name = "GENERAL5")
    private String general5;

    public ServiceIntro() {
    }

    public ServiceIntro(BigDecimal id) {
        this.id = id;
    }

    public BigDecimal getId() {
        return id;
    }

    public void setId(BigDecimal id) {
        this.id = id;
    }

    public String getServiceTitle() {
        return serviceTitle;
    }

    public void setServiceTitle(String serviceTitle) {
        this.serviceTitle = serviceTitle;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public byte[] getImage() {
        return image;
    }

    public void setImage(byte[] image) {
        this.image = image;
    }

    public String getShortDescription() {
        return shortDescription;
    }

    public void setShortDescription(String shortDescription) {
        this.shortDescription = shortDescription;
    }

    public String getLongDescription() {
        return longDescription;
    }

    public void setLongDescription(String longDescription) {
        this.longDescription = longDescription;
    }

    public String getGeneral2() {
        return general2;
    }

    public void setGeneral2(String general2) {
        this.general2 = general2;
    }

    public String getGeneral3() {
        return general3;
    }

    public void setGeneral3(String general3) {
        this.general3 = general3;
    }

    public String getGeneral4() {
        return general4;
    }

    public void setGeneral4(String general4) {
        this.general4 = general4;
    }

    public String getGeneral5() {
        return general5;
    }

    public void setGeneral5(String general5) {
        this.general5 = general5;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ServiceIntro)) {
            return false;
        }
        ServiceIntro other = (ServiceIntro) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.thienloc.omap.entity.ServiceIntro[ id=" + id + " ]";
    }
    
    //my code
    @Transient
    private StreamedContent imageStream;

    public StreamedContent getImageStream() {
        if (image != null) {
            imageStream = new DefaultStreamedContent(new ByteArrayInputStream(image), "image/jpg");
            return imageStream;
        } else {
            return null;
        }

    }
}
